package com.qianda.qdminiapp.common.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.qianda.qdminiapp.config.RabbitConfig;
import com.qianda.qdminiapp.service.CommondManager;
import com.qianda.qdminiapp.service.order.BalancePaymentImpl;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.impl.AMQImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * 消息消费者，协议版本为1的设备发送出巾指令
 * @ClassName MsgReceiverForProtocolA
 * @Author cw
 * @Date 2019/8/8 11:25
 * @Version 1.0
 */
//@Component
//@RabbitListener(queues = RabbitConfig.QUEUE_A)
public class MsgReceiverForProtocolA {

    private static Logger LOGGER = LoggerFactory.getLogger(MsgReceiverForProtocolA.class);

    @Autowired
    private CommondManager commondManager;

    @RabbitHandler
    public void process(String content) throws IOException {
        LOGGER.info("开始消费消息，执行出巾指令");
        Map<String,Object> data  = (Map<String, Object>) JSON.parse(content);
        String orderId = (String) data.get("orderId");
        commondManager.startCreateTowel(orderId);
      //  channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
    }
}
